#include <iostream>
#include <iomanip>
using namespace std;

class M33{
public:
	M33 (void) {
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				m_a[i][j] = {0};
			}
		}
	}
	M33 (int a[][3]) {
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				m_a[i][j] = a[i][j];
			}
		}
	}
	friend ostream& operator<< (ostream& os, const M33& m) {
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				//setw() --> 设置位宽
				os << setw(4) <<m.m_a[i][j];
			}
			os << endl;
		}
		return os;
	}
	//双目:+
	const M33 operator+ (const M33& m) const {
		int a[3][3] = {0};
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				a[i][j] = m_a[i][j] + m.m_a[i][j];
			}
		}
		return M33(a);
	}
	//双目:-
	const M33 operator- (const M33& m) const {
		int a[3][3] = {0};
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				a[i][j] = m_a[i][j] - m.m_a[i][j];
			}
		}
		return M33(a);
	}
	//双目:*
	const M33 operator* (const M33& m) const {
		int a[3][3] = {0};
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				for (int k = 0; k < 3; k++) {
					a[i][j] += m_a[i][k] * m.m_a[k][j];
				}
			}
		}
		return M33(a);
	}
	//双目: += 
	M33& operator+= (const M33& m) {
		*this = *this + m;
		return *this;
	}
	//双目: -= 
	M33& operator-= (const M33& m) {
		*this = *this - m;
		return *this;
	}
	//双目: *= 
	M33& operator*= (const M33& m) {
		*this = *this * m;
		return *this;
	}
	//单目: - (取负)
	const M33 operator- (void) {
		//M33 ();
		M33 tmp;
		return tmp - *this;
	}
	

private:
	int m_a[3][3];
};

int main (void)
{
	int a1[3][3] = {1,2,3,4,5,6,7,8,9};
	int a2[3][3] = {9,8,7,6,5,4,3,2,1};
	M33 m1(a1);
	M33 m2(a2);
	cout << m1 << endl;
	cout << m2 << endl;

	cout << "m1+m2 = "<< endl;
	cout << m1 + m2 << endl;
	cout << "m1-m2" << endl;
	cout << m1 - m2 << endl;
	cout << "m1*m2" << endl;
	cout << m1 * m2 << endl;

	cout << "m1 += m2" << endl;
	m1 += m2;
	cout << m1 << endl;
	cout << "m1 -= m2" << endl;
	m1 -= m2;
	cout << m1 << endl;
	cout << "m1 *= m2" << endl;
	m1 *= m2;
	cout << m1  << endl;

	cout << "-m1" << endl;
	cout << -m1 << endl;

	return 0;
}
